$(function () {

    $("a").on("click", function () {
        var methods = $(this).data("method");
        if(methods){
            itsource[methods]();
        }
    });

    var detaildatagrid = $("#detaildatagrid");
    var ff = $("#ff");

    detaildatagrid.datagrid({
        url: 'Consunables/Pagequery',
        fit:true,
        title:'支出明细',
        rownumbers:true,
        pagination:true,
        pagePosition:'top',
        singleSelect:true,
        toolbar:"#toolbar",
        fitColumns:true,
        columns: [[
            /*使用遍历:遍历的是Velocity中上下文的对象:
            * fieldList
            *                  {field: 'id', title: 'id', width: '10%',align:  'center'},
            * */
            {field: 'id', title: '编号',align:  'center'},
            {field: 'name', title: '名称', width: '24%',align:  'center'},
            {field: 'date', title: '时间', width: '25%',align:  'center'},
            {field: 'num', title: '数量', width: '25%',align:  'center'},
            {field: 'price', title: '价格', width: '25%',align:  'center'}
        ]]
    });

    var itsource={

        "search":function () {
           /* console.debug("search");*/
            //如果点击的是搜索提交from表单
            $('#ff').form("submit",{
                url:"Consunables/search",
                onSubmit: function(){
                    return true
                },
                success:function(data){
                    var data = $.parseJSON(data);
                    detaildatagrid.datagrid("loadData",data);
                 }
            });
        },
        //点击每日支出弹出饼图
        'day':function (o) {
            pieFunction( '当日',1);
        },
        'week':function (o) {
            pieFunction( '本周',2);
        },
        'yue':function (o) {
            pieFunction( '本月',3);
        }
    }

    function pieFunction(time,term) {
        detaildatagrid.datagrid("load",{"term":term});
    }

})